#include "thread.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

void* fun(void* arg) {
    long v = (long) arg;
    for(int i = 0 ; i < 10 ; i++,v++) {
        printf("thread with arg: %ld\n", (long)arg);
        sleep(1);
        thread_yield();
    }
    return (void*)v;
}

int
main(void) {
    thread_t t0;
    thread_t t1;

    thread_create(&t0, fun, (void*)0);
    thread_create(&t1, fun, (void*)1);

    long result;

    thread_join(t0, (void**)&result);
    printf("t0 ended with return value: %ld\n", result);

    thread_join(t1, (void**)&result);
    printf("t1 ended with return value: %ld\n", result);
}
